<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>{{ count }}</strong></span
    >
    <!-- 给ul绑定一个点击事件，li可以通过冒泡触发 -->
    <ul class="filters" @click="fn">
      <!-- 设置一个变量，通过点击改变变量值来动态给li添加class高亮样式 -->
      <li>
        <a
          :class="{ selected: isDone === 'all' }"
          href="javascript:;"
          @click="isDone = 'all'"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: isDone === 'no' }"
          href="javascript:;"
          @click="isDone = 'no'"
          >未完成</a
        >
      </li>
      <li>
        <a
          :class="{ selected: isDone === 'yes' }"
          href="javascript:;"
          @click="isDone = 'yes'"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="cleanFn">清除已完成</button>
  </footer>
</template>

<script>
export default {
  data() {
    return {
      isDone: "all",
    };
  },
  props: ["list"],
  methods: {
    fn() {
      // console.log(this.isDone);
      this.$emit("fun", this.isDone);
    },
    cleanFn(){
        // console.log(1);
        // 触发父组件clean事件，不传参
        this.$emit('clean')
    }
  },
  computed: {
    count() {
      return this.list.length;
    },
  },
};
</script>